package turtle.system.invest.evaluate;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;

import org.osite.util.ToolKit;

public class FindTop1000 {

	private static final int N = 1000;
	private static final int SORTED_COL = 0;
	
	private static class Record {
		private String line;
		private double value;
		
		public Record(String line) {
			this.line = line;
			int index = line.indexOf(')');
			String token[] = line.substring(index + 2).split(",");
			value = Double.parseDouble(token[SORTED_COL]);
		}
	}
	
	private static class RecordComparator implements Comparator<Record> {
		@Override
		public int compare(Record o1, Record o2) {
			return Double.compare(o1.value, o2.value);
		}
	}
	
	public static void main(String argv[]) throws Exception {
		BufferedReader reader = 
				new BufferedReader(new FileReader("output.log"));
		PriorityQueue<Record> heap =
				new PriorityQueue<Record>(N, new RecordComparator());
		
		String line = reader.readLine();
		while (line != null) {
			Record record = new Record(line);
			if (heap.size() < N) {
				heap.add(record);
			} else if (record.value > heap.element().value) {
				heap.remove();
				heap.add(record);
			}
			line = reader.readLine();
		}
		
		ArrayList<Record> topN = ToolKit.newArrayList();
		topN.addAll(heap);
		Collections.sort(topN, new RecordComparator());
		for (Record record : topN) {
			System.out.println(record.line);
		}
		
	}
}
